#include "game_solver.hh"
#include <iostream>
#include <string>

int main(void)
{


  std::string names[4] = {std::string("pierre  "),
			  std::string("feuille "),
			  std::string("sciseaux"),
			  std::string("puit    ") };
		  
  
  Matrix<double> rewards(4,4);
  signed nrows = 4;
  signed ncols = 4;

  // pierre         feuille            sciseaux           puit
  rewards(0,0) = 0; rewards(0,1) = -1; rewards(0,2) = +1; rewards(0,3) = -1; // pierre
  rewards(1,0) = +1; rewards(1,1) = 0; rewards(1,2) = -1; rewards(1,3) = +1; // feuille
  rewards(2,0) = -1; rewards(2,1) = +1; rewards(2,2) = 0; rewards(2,3) = -1; // sciseaux
  rewards(3,0) = +1; rewards(3,1) = -1; rewards(3,2) = +1; rewards(3,3) = 0; // puit

  
  // Display game reward matrix.
  dump(std::cout,rewards);


  Matrix<double> Alice;
  Matrix<double> Bob;

  double reward = solve(rewards,Alice,Bob,0);
  std::cout << "Alice expected reward with uniform strategy: " << reward << std::endl;

  reward = solve(rewards,Alice,Bob,20000);

  std::cout << "Optimal strategy for Alice:" << std::endl;
  for(unsigned j=0;j!=4; ++j)
    {
      std::cout << "P(" << names[j] << ") = " << Alice(0,j) << std::endl;
    }

  std::cout << "Alice expected reward: " << reward << std::endl;

  std::cout << "Optimal strategy for Bob:" << std::endl;
  for(unsigned i=0;i!=4; ++i)
    {
      std::cout << "P(" << names[i] << ") = " << Bob(i,0) << std::endl;
    }
  std::cout << std::endl;
  

  srandom(time(NULL)); // Seed random number generator.
  
  nrows = ncols = 10;
  rewards.resize(nrows,ncols);

  
  // Initialize matrix with random values.
  for ( int row = 0 ; row < nrows ; row++ ) {
    for ( int col = 0 ; col < ncols ; col++ ) {
      rewards(row,col) = (double)(random()%100);
    }
  }

  // Display game reward matrix.
  dump(std::cout,rewards);

  reward = solve(rewards,Alice,Bob,0);
  std::cout << "Alice expected reward with uniform strategy: " << reward << std::endl;

  reward = solve(rewards,Alice,Bob,1000);

  std::cout << "Optimal strategy for Alice:" << std::endl;
  for(signed j=0;j!=Alice.columns(); ++j)
    {
      std::cout << "P(option " << j << ") = " << Alice(0,j) << std::endl;
    }

  std::cout << "Alice expected reward: " << reward << std::endl;

  std::cout << "Optimal strategy for Bob:" << std::endl;
  for(signed i=0;i!=Bob.rows(); ++i)
    {
      std::cout << "P(option " << i << ") = " << Bob(i,0) << std::endl;
    }

  

  return 0;
}
